package com.yungu.swift.admin.route.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.base.CurrentUser;
import com.yungu.swift.admin.consts.AdminErrorEnum;
import com.yungu.swift.assets.driver.model.param.AdminCrosstownAssignPageParam;
import com.yungu.swift.assets.driver.service.DriverQueueService;
import com.yungu.swift.assets.passenger.model.dto.PassengerDto;
import com.yungu.swift.assets.passenger.service.PassengerService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminParam;
import com.yungu.swift.base.model.annotation.ResponseImgOverride;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.constants.OrderConstant;
import com.yungu.swift.order.model.param.*;
import com.yungu.swift.order.model.vo.AdminChildOrderInfoVo;
import com.yungu.swift.order.model.vo.AdminJoinCountVo;
import com.yungu.swift.order.model.vo.AdminMainOrderInfoVo;
import com.yungu.swift.order.model.vo.ApiJoinValuationVo;
import com.yungu.swift.order.model.vo.JsonOrderDetailVo;
import com.yungu.swift.order.service.OrderAdminService;
import com.yungu.swift.order.service.OrderAssignService;
import com.yungu.swift.order.service.OrderFareService;
import com.yungu.swift.order.service.OrderJoinService;
import com.yungu.swift.order.service.RefundService;
import com.yungu.swift.system.sys.model.param.AdminRouteParam;
import com.yungu.swift.utils.MapUtils;
import com.yungu.swift.utils.ParamUtil;
import com.yungu.swift.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author : cuixiuyin
 * @date : 2019/7/16
 */
@Slf4j
@RestController
@RequestMapping("/admin/v1/order/join")
@Api(value = "【订单管理】", tags = "跨城拼车订单操作接口")
public class OrderJoinAdmin {

    @Reference
    private OrderAdminService orderAdminService;
    @Reference
    private OrderJoinService orderJoinService;
    @Reference
    private RefundService refundService;
    @Reference
    private DriverQueueService driverQueueService;
    @Reference
    private OrderAssignService orderAssignService;
    @Reference
    private OrderFareService orderFareService;
    @Reference
    private PassengerService passengerService;


    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ApiOperation(value = "新建跨城订单", httpMethod = "POST")
    public ResponseData<Map<String,Object>> createOrder(@RequestBody AdminJoinOrderParam adminJoinParam) {
        if (ParamUtil.isIllegal(adminJoinParam.getTypeTime(), adminJoinParam.getOriginUuid(), adminJoinParam.getDestUuid(),
                adminJoinParam.getTypeJoin())) {
            return ResponseData.buildErrorResponse(AdminErrorEnum.PARAM_ERROR.getCode(), AdminErrorEnum.PARAM_ERROR.getMsg());
        }
        // 新建小件订单
        if (CommonConstant.ORDER_TYPE_JOIN_PARCEL == adminJoinParam.getTypeJoin()) {
            if (ParamUtil.isIllegal(adminJoinParam.getSenderMobile(), adminJoinParam.getReceiverMobile(), adminJoinParam.getSysWayCalculationUuid())) {
                return ResponseData.buildErrorResponse(AdminErrorEnum.PARAM_ERROR.getCode(), AdminErrorEnum.PARAM_ERROR.getMsg());
            }
        }else{
            if (ParamUtil.isIllegal(adminJoinParam.getPassengerMobile(), adminJoinParam.getCarModelUuid())) {
                return ResponseData.buildErrorResponse(AdminErrorEnum.PARAM_ERROR.getCode(), AdminErrorEnum.PARAM_ERROR.getMsg());
            }
        }
        JoinOrderParam joinOrderParam = new JoinOrderParam();
        BeanUtils.copyProperties(adminJoinParam, joinOrderParam);
        joinOrderParam.setOriginSiteUuid(adminJoinParam.getOriginUuid());
        joinOrderParam.setDestSiteUuid(adminJoinParam.getDestUuid());
        joinOrderParam.setPassengerLng(String.valueOf(adminJoinParam.getOriginLng()));
        joinOrderParam.setPassengerLat(String.valueOf(adminJoinParam.getOriginLat()));
        joinOrderParam.setTypeModule(CommonConstant.BUSINESS_TYPE_POOL);
        return orderJoinService.createCrosstownOrder(joinOrderParam);
    }

    @RequestMapping(value = "/close", method = RequestMethod.POST)
    @ApiOperation(value = "关闭跨城订单", httpMethod = "POST")
    public ResponseData<Boolean> close(@RequestBody AdminJoinCloseParam joinCloseParam) {
        if (ParamUtil.isIllegal(joinCloseParam.getBusinessType(), joinCloseParam.getOrderUuid(), joinCloseParam.getRemark())) {
            AdminErrorEnum paramError = AdminErrorEnum.PARAM_ERROR;
            return ResponseData.buildErrorResponse(paramError.getCode(), paramError.getMsg());
        }
        JoinOrderParam joinOrdeParam = new JoinOrderParam();
        joinOrdeParam.setOrderUuid(joinCloseParam.getOrderUuid());
        joinOrdeParam.setCloseType("ADMIN_CLOSE");
        joinOrdeParam.setCloseReason(joinCloseParam.getRemark());
        joinOrdeParam.setTypeModule(joinCloseParam.getBusinessType());
        return orderJoinService.closeJoinOrder(joinOrdeParam);
    }

    @ResponseImgOverride
    @RequestMapping(value = "/notAssignJoinOrderPage", method = RequestMethod.POST)
    @ApiOperation(value = "获取未派单跨城拼车与小件订单", httpMethod = "POST")
    public ResponseData<PageVo<AdminChildOrderInfoVo>> notAssignJoinOrderPage(@RequestBody AdminJoinRelateParam joinRelateParam) {
        return orderAdminService.notAssignJoinOrderPage(joinRelateParam);
    }

    @ResponseImgOverride
    @RequestMapping(value = "/yetAssignJoinOrderPage", method = RequestMethod.POST)
    @ApiOperation(value = "获取已指派司机的跨城拼车与小件订单", httpMethod = "POST")
    public ResponseData<PageVo<AdminMainOrderInfoVo>> yetAssignJoinOrderPage(@RequestBody AdminJoinRelateParam joinRelateParam) {
        return orderAdminService.yetAssignJoinOrderPage(joinRelateParam);
    }

    @RequestMapping(value = "/assignDriver", method = RequestMethod.POST)
    @ApiOperation(value = "获取订单可派单司机", httpMethod = "POST")
    public ResponseData assignDriver(@RequestBody AdminCrosstownAssignQueryParam admiParam) {
        if (ParamUtil.isIllegal(admiParam.getOrderUuid(), admiParam.getWayUuid())) {
            AdminErrorEnum paramError = AdminErrorEnum.PARAM_ERROR;
            return ResponseData.buildErrorResponse(paramError.getCode(), paramError.getMsg());
        }
        //权限过滤
        switch (admiParam.getType()) {
            //已收车
            case 0: {
                AdminCrosstownAssignPageParam assetsParam = new AdminCrosstownAssignPageParam();
                BeanUtils.copyProperties(admiParam, assetsParam);
                return driverQueueService.queryFreeDriver(assetsParam);
            }
            //排队中queryQueueDriver
            case 1: {
                AdminCrosstownAssignPageParam assetsParam = new AdminCrosstownAssignPageParam();
                BeanUtils.copyProperties(admiParam, assetsParam);
                assetsParam.setMergeAssign(false);
                return driverQueueService.queryByAssign(assetsParam);
            }
            //待出发
            case 2: {
                admiParam.setJoinStatus(OrderConstant.ORDER_JOIN_STATUS_WAIT_START);
                admiParam.setMergeAssign(false);
                return orderAdminService.queryByAssign(admiParam);
            }
            default:
                return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "请求数据类型异常");
        }
    }

    @RequestMapping(value = "/countJoinOrder", method = RequestMethod.POST)
    @ApiOperation(value = "跨城订单状态相关数量", httpMethod = "POST")
    public ResponseData<AdminJoinCountVo> countJoinOrder(@RequestBody AdminParam adminParam) {
        return orderAdminService.countJoinOrder(adminParam);
    }

    @RequestMapping(value = "/subscribe", method = RequestMethod.POST)
    @ApiOperation(value = "跨城订单预约确认", httpMethod = "POST")
    public ResponseData<Boolean> subscribe(@RequestBody AdminOrderUuidParam orderUuidParam) {
        if (StringUtils.isEmpty(orderUuidParam.getOrderUuid())) {
            AdminErrorEnum paramError = AdminErrorEnum.PARAM_ERROR;
            return ResponseData.buildErrorResponse(paramError.getCode(), paramError.getMsg());
        }
        return orderJoinService.subscribeJoinOrder(orderUuidParam.getOrderUuid(), orderUuidParam.getUserUuid());
    }

    @RequestMapping(value = "/doAssign", method = RequestMethod.POST)
    @ApiOperation(value = "跨城订单手动派单", httpMethod = "POST")
    public ResponseData<JsonOrderDetailVo> doAssign(@RequestBody CrosstownAssignOrderParam crosstownAssignOrderParam) {
        return orderAssignService.doAssignJoinOrder(crosstownAssignOrderParam);
    }

    @RequestMapping(value = "/editOrderInfo", method = RequestMethod.POST)
    @ApiOperation(value = "跨城修改派单前的订单信息", httpMethod = "POST")
    public ResponseData<Boolean> editOrderInfo(@RequestBody AdminOrderEditParam adminOrderEditParam) {
        return orderJoinService.crosstownEditOrderInfo(adminOrderEditParam);
    }

    @RequestMapping(value = "/editAssignOrder", method = RequestMethod.POST)
    @ApiOperation(value = "跨城修改派单后的订单信息", httpMethod = "POST")
    public ResponseData<Boolean> editAssignOrder(@RequestBody AdminOrderEditParam adminOrderEditParam) {
        return orderJoinService.editAssignOrder(adminOrderEditParam);
    }

    @RequestMapping(value = "/mergeAssignQuery", method = RequestMethod.POST)
    @ApiOperation(value = "合并派单窗口查询", httpMethod = "POST")
    public ResponseData mergeAssignVerify(@RequestBody AdminCrosstownAssignQueryParam admiParam) {
        switch (admiParam.getType()) {
            //已收车
            case 0: {
                AdminCrosstownAssignPageParam assetsParam = new AdminCrosstownAssignPageParam();
                BeanUtils.copyProperties(admiParam, assetsParam);
                return driverQueueService.queryFreeDriver(assetsParam);
            }
            //排队中queryQueueDriver
            case 1: {
                AdminCrosstownAssignPageParam assetsParam = new AdminCrosstownAssignPageParam();
                BeanUtils.copyProperties(admiParam, assetsParam);
                assetsParam.setNoOrder(1);
                assetsParam.setMergeAssign(true);
                return driverQueueService.queryByAssign(assetsParam);
            }
            //待出发
            case 2: {
                admiParam.setJoinStatus(OrderConstant.ORDER_JOIN_STATUS_WAIT_START);
                admiParam.setMergeAssign(true);
                return orderAdminService.queryByAssign(admiParam);
            }
            default:
                return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "请求数据类型异常");
        }
    }

    @PostMapping("/mergeAssignPreHandle")
    @ApiOperation(value = "合并派单打开窗口前预处理", httpMethod = "POST")
    public ResponseData<Boolean> mergeAssignPreHandle(@RequestBody MergeAssignParam mergeAssignParam) {
        return orderJoinService.mergeAssignPreHandle(mergeAssignParam);
    }

    @PostMapping("/mergeAssignVerify")
    @ApiOperation(value = "合并派单指派校验", httpMethod = "POST")
    public ResponseData mergeAssignVerify(@RequestBody MergeAssignParam mergeAssignParam) {
        return orderJoinService.mergeAssignVerify(mergeAssignParam);
    }

    @PostMapping("/doMergeAssign")
    @ApiOperation(value = "合并派单", httpMethod = "POST")
    public ResponseData<Boolean> doMergeAssign(@RequestBody MergeAssignParam mergeAssignParam) {
        return orderAssignService.doMergeAssign(mergeAssignParam);
    }

    @PostMapping("/getParcelTag")
    @ApiOperation(value = "获得小件标签", httpMethod = "POST")
    public ResponseData<Map<String, Object>> getParcelTag(@RequestBody AdminRouteParam routeParam) {
        JoinOrderParam joinOrderParam = new JoinOrderParam();
        joinOrderParam.setOriginSiteUuid(routeParam.getOriginSiteUuid());
        joinOrderParam.setDestSiteUuid(routeParam.getDestSiteUuid());
        joinOrderParam.setAppid(routeParam.getAppid());
        return orderJoinService.getParcelTag(joinOrderParam);
    }

    @RequestMapping(value = {"/parcel/evaluate"})
    @ApiOperation(value = "小件估价接口 —— 已生效", response = Map.class, notes = "响应数据结构参照专/快车系列，以实际接口返回为准")
    public ResponseData<Map<String, Object>> parcelEvaluate(@RequestBody JoinOrderParam joinOrdeParam, @CurrentUser AdminParam adminParam) {
        joinOrdeParam.setAppid(adminParam.getAppid());
        if (StringUtils.isNotBlank(joinOrdeParam.getSenderMobile())) {
            PassengerDto passengerDto = passengerService.get(MapUtils.build("mobile", joinOrdeParam.getSenderMobile())).getData();
            if (passengerDto != null) {
                joinOrdeParam.setPassengerUuid(passengerDto.getUuid());
            }
        }
        return orderFareService.parcelValuation(joinOrdeParam);
    }

    @RequestMapping(value = {"/evaluate"})
    @ApiOperation(value = "拼车估价接口 —— 已生效", response = Map.class, notes = "响应数据结构参照专/快车系列，以实际接口返回为准")
    public ResponseData<ApiJoinValuationVo> evaluate(@RequestBody OrderEvaluateParam evaluateParam, @CurrentUser AdminParam adminParam) {
        evaluateParam.setAppid(adminParam.getAppid());
        if (StringUtils.isNotBlank(evaluateParam.getPassengerMobile())) {
            PassengerDto passengerDto = passengerService.get(MapUtils.build("mobile", evaluateParam.getPassengerMobile())).getData();
            if (passengerDto != null) {
                evaluateParam.setPassengerUuid(passengerDto.getUuid());
            }
        }
        if (StringUtils.isNull(evaluateParam.getDeparTime())) {
            evaluateParam.setDeparTime(new Date());
        }
        return orderFareService.joinValuation(evaluateParam);
    }

    @RequestMapping(value = "/exportYetAssignJoinOrder", method = RequestMethod.POST)
    @ApiOperation(value = "导出已指派订单", httpMethod = "POST")
    public void exportYetAssignJoinOrder(@RequestBody AdminJoinRelateParam joinRelateParam, HttpServletResponse response) throws Exception {
        ResponseData<List<AdminMainOrderInfoVo>> responseData = orderAdminService.exportYetAssignJoinOrder(joinRelateParam);
        List<AdminMainOrderInfoVo> resultList = responseData.getData();
        try (OutputStream os = response.getOutputStream()) {
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.createSheet();
            //宽度5.38
            sheet.setColumnWidth(0, ((5 + 1) * 7 + 5) / 7 * 256);
            //宽度50.38
            sheet.setColumnWidth(1, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(2, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(3, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(4, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(5, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(6, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(7, ((25 + 1) * 7 + 5) / 7 * 256);
            sheet.setColumnWidth(8, ((25 + 1) * 7 + 5) / 7 * 256);

            //创建第一行
            Row row = sheet.createRow(0);
            row.createCell(0).setCellValue("序号");
            row.createCell(1).setCellValue("订单号");
            row.createCell(2).setCellValue("下单时间");
            row.createCell(3).setCellValue("出发时间");
            row.createCell(4).setCellValue("线路");
            row.createCell(5).setCellValue("乘客信息");
            row.createCell(6).setCellValue("司机信息");
            row.createCell(7).setCellValue("状态");
            row.createCell(8).setCellValue("异常备注");

            writeMainOrderRow(sheet, resultList, workbook);

            response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode("OrderInfo.xlsx", "UTF-8"));
            response.setContentType("application/octet-stream");
            response.setCharacterEncoding("utf-8");
            workbook.write(os);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/mainOrderDetail", method = RequestMethod.POST)
    @ApiOperation(value = "跨城主单详情", httpMethod = "POST")
    public ResponseData<Map<String,Object>> mainOrderDetail(@RequestBody Map<String,String> map) {
        String mainOrderUuid = map.get("mainOrderUuid");
        if(mainOrderUuid==null){
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE,"主单ID不能为空");
        }
        return orderAdminService.mainOrderDetail(mainOrderUuid);
    }

    /**
     * 创建主订单信息行
     */
    private void writeMainOrderRow(XSSFSheet sheet, List<AdminMainOrderInfoVo> resultList, XSSFWorkbook workbook) {
        int rowNum = 1;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        XSSFCellStyle mainStyle = workbook.createCellStyle();
        mainStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
        mainStyle.setFillForegroundColor(IndexedColors.LIGHT_YELLOW.getIndex());
        mainStyle.setAlignment(XSSFCellStyle.ALIGN_LEFT);
        mainStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        XSSFFont font = workbook.createFont();
        //粗体显示
        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
        mainStyle.setFont(font);
        mainStyle.setWrapText(true);

        XSSFCellStyle childStyle = workbook.createCellStyle();
        childStyle.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
        childStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        childStyle.setWrapText(true);
        int sequenceNumber = 1;
        for (int i = 0; i < resultList.size(); i++) {
            XSSFRow dataRow = sheet.createRow(rowNum);
            XSSFCell sequenceNumberCell = dataRow.createCell(0);
            sequenceNumberCell.setCellStyle(mainStyle);
            sequenceNumberCell.setCellValue(sequenceNumber);
            sequenceNumber++;
            AdminMainOrderInfoVo mainOrderInfoVo = resultList.get(i);
            for (int cellNum = 1; cellNum <= 8; cellNum++) {
                XSSFCell cell = dataRow.createCell(cellNum);
                cell.setCellStyle(mainStyle);
                switch (cellNum) {
                    case 1: {
                        //订单号
                        cell.setCellValue(mainOrderInfoVo.getMainOrderNo());
                        break;
                    }
                    case 2: {
                        //下单时间
                        cell.setCellValue(dateFormat.format(mainOrderInfoVo.getCreateOn()));
                        break;
                    }
                    case 3: {
                        //出发时间
                        cell.setCellValue("-");
                        break;
                    }
                    case 4: {
                        //线路
                        String wayName = mainOrderInfoVo.getOriginName() + "-" + mainOrderInfoVo.getDestName();
                        //拼车类型
                        String typeJoin = getTypeModule(mainOrderInfoVo.getTypeJoin());
                        if (mainOrderInfoVo.getOrderDemand() != null && mainOrderInfoVo.getOrderDemand() == 2) {
                            typeJoin = typeJoin + "-" + "机场专线";
                        }
                        cell.setCellValue(typeJoin + "\n" + wayName);
                        break;
                    }
                    case 5: {
                        //乘客信息
                        cell.setCellValue("拼单数：" + mainOrderInfoVo.getJoinOrderNum() + "\n" + "乘客数：" + mainOrderInfoVo.getAdultNumTotal() + "\n" + "带货数：" + mainOrderInfoVo.getParcelOrderNum());
                        break;
                    }
                    case 6: {
                        //司机信息
                        cell.setCellValue("姓名：" + mainOrderInfoVo.getDriverName() + "\n" + "手机号：" + mainOrderInfoVo.getDriverMobile() +
                                "\n" + "车型：" + mainOrderInfoVo.getCarModelName() + "\n" + "车牌：" + mainOrderInfoVo.getPlateNum());
                        break;
                    }
                    case 7: {
                        //状态
                        cell.setCellValue("-");
                        break;
                    }
                    case 8: {
                        //异常备注
                        cell.setCellValue("-");
                        break;
                    }
                    default:
                        break;
                }
            }
            rowNum = writeChlidOrderRow(sheet, mainOrderInfoVo, rowNum, dateFormat, childStyle);
            rowNum++;
        }
    }

    /**
     * 创建子订单信息行
     */
    private int writeChlidOrderRow(XSSFSheet sheet, AdminMainOrderInfoVo mainOrderInfoVo, Integer rowNum, SimpleDateFormat dateFormat, XSSFCellStyle childStyle) {
        List<AdminChildOrderInfoVo> chlidOrderList = mainOrderInfoVo.getChildOrderInfoVoList();
        if (chlidOrderList != null) {
            for (int i = 0; i < chlidOrderList.size(); i++) {
                rowNum++;
                XSSFRow dataRow = sheet.createRow(rowNum);
                AdminChildOrderInfoVo childOrderInfoVo = chlidOrderList.get(i);
                for (int cellNum = 1; cellNum <= 8; cellNum++) {
                    XSSFCell cell = dataRow.createCell(cellNum);
                    cell.setCellStyle(childStyle);
                    switch (cellNum) {
                        case 1: {
                            //订单号
                            cell.setCellValue(childOrderInfoVo.getOrderNo());
                            break;
                        }
                        case 2: {
                            //下单时间
                            cell.setCellValue(dateFormat.format(childOrderInfoVo.getCreateOn()));
                            break;
                        }
                        case 3: {
                            //出发时间
                            cell.setCellValue(dateFormat.format(childOrderInfoVo.getDeparTime()));
                            break;
                        }
                        case 4: {
                            //线路
                            cell.setCellValue("出发地：" + childOrderInfoVo.getOriginDetailAddress() + "\n" + "目的地：" + childOrderInfoVo.getDestDetailAddress());
                            break;
                        }
                        case 5: {
                            //乘客信息
                            String passengerInfo = "手机号：" + childOrderInfoVo.getActualPasMob() + "\n" + "备注：" + (StringUtils.isEmpty(childOrderInfoVo.getRemark()) ? "无" : childOrderInfoVo.getRemark());
                            if (CommonConstant.ORDER_TYPE_JOIN_PARCEL == childOrderInfoVo.getTypeJoin()) {
                                passengerInfo = "小件" + "\n" + passengerInfo;
                            }
                            cell.setCellValue(passengerInfo);
                            break;
                        }
                        case 6: {
                            //状态
                            cell.setCellValue(getJoinStatus(childOrderInfoVo.getJoinStatus()));
                            break;
                        }
                        case 7: {
                            //是否关闭
                            cell.setCellValue(childOrderInfoVo.getCloseStatus() == OrderConstant.ORDER_CLOSE_STATUS_NORMAL ? "正常" : "已关闭");
                            break;
                        }
                        case 8: {
                            //异常备注
                            cell.setCellValue(getTypeAbnormal(childOrderInfoVo.getTypeAbnormal()));
                            break;
                        }
                        default:
                            break;
                    }
                }
            }
        }
        return rowNum;
    }

    /**
     * 获取订单类型
     */
    private String getTypeModule(Integer typeJoin) {
        switch (typeJoin) {
            case 1:
                return "经济拼车";
            case 2:
                return "包车";
            case 3:
                return "跨城小件";
            case 4:
                return "二人快车";
            default:
                return "";
        }
    }

    /**
     * 异常备注
     */
    private String getTypeAbnormal(Integer typeAbnormal) {
        if (typeAbnormal == null) {
            return "";
        }
        switch (typeAbnormal) {
            case 1:
                return "乘客修改目的地";
            case 2:
                return "司机绕路";
            case 3:
                return "乘客要求变更路线";
            case 4:
                return "乘客中途下车";
            case 5:
                return "车辆故障";
            case 6:
                return "交通事故";
            default:
                return "";
        }
    }

    /**
     * 订单状态
     */
    private String getJoinStatus(Integer joinStatus) {
        switch (joinStatus) {
            case 100:
                return "新建订单";
            case 200:
                return "已确认";
            case 300:
                return "预约成功";
            case 400:
                return "待出发";
            case 410:
                return "行程开始";
            case 420:
                return "待上车";
            case 430:
                return "已上车";
            case 500:
                return "行程中";
            case 510:
                return "待确认费用";
            case 520:
                return "待司机支付";
            case 530:
                return "待乘客支付";
            case 600:
                return "已完成";
            case 700:
                return "已评价";
            default:
                return "状态异常";
        }
    }

    @RequestMapping(value = "/reAssign", method = RequestMethod.POST)
    @ApiOperation(value = "跨城订单重新派单", httpMethod = "POST")
    public ResponseData<Boolean> reAssign(@RequestBody Map<String,String> map) {
        String orderUuid = map.get("orderUuid");
        if(StringUtils.isEmpty(orderUuid)){
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE,"订单ID不能为空");
        }
        return orderAdminService.reAssign(orderUuid);
    }
}
